package server;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.SocketException;

import javax.swing.text.Style;

import shared.Packet;

public class ClientConnection {
    public TestingServer host;
    public String name;
    public Style style;
    public Socket connection;
    public ObjectOutputStream out;
    public ObjectInputStream in;
    public boolean isConnected;

    public ClientConnection(Socket connection, TestingServer host){
        this.isConnected = false;
        this.host = host;
        this.connection = connection;
        this.name = "TempUsername";
        try {
            out = new ObjectOutputStream(connection.getOutputStream());
            in = new ObjectInputStream(connection.getInputStream());
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

        ReceivePacketThread receive = new ReceivePacketThread(this);
        receive.start();
    }
    public void sendPacket(Packet packet){
        try{
            out.writeObject(packet);
            out.flush();
        }catch(SocketException e){
            // Seems Safe
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}
